package org.ChrisRiffle.Acme.BoundingBox.ui;

import java.awt.BorderLayout;

import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.LayoutStyle.ComponentPlacement;

import org.ChrisRiffle.Acme.BoundingBox.controlers.QueryPanelControler;

/**
 * BoxQueryDialog
 * 
 * @author RIF
 */
public class BoxQueryDialog extends JDialog {

	
	private static final String TITLE = "Acme Bounding Box";
	
	
	// used to display 'loading...' during work
	private JPanel loadingPanel;
	

    /**
	 * Constructor
	 */
	public BoxQueryDialog() {
	
		configDialog();
	}



	/**
     * Gets the loadingPanel
     * 
     * Used to display 'loading...' during work
     * 
     * @return the loadingPanel
     */
    public JPanel getLoadingPanel() {
	
	if(loadingPanel == null){
	    
	    loadingPanel = new JPanel();
	    
	    GroupLayout groupLayout = new GroupLayout(loadingPanel);
	    loadingPanel.setLayout(groupLayout);
	    
	    
	    JLabel loadingLabel = new JLabel("Loading...");
	    
	    // use these horiz/vert gaps to put the label in the middle
	    
	    //horizontal group
	    groupLayout.setHorizontalGroup(groupLayout.createSequentialGroup()
		    
		    .addPreferredGap(ComponentPlacement.UNRELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
		    .addComponent(loadingLabel)
		    .addPreferredGap(ComponentPlacement.UNRELATED,  GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	    );
	    
	    
	    //vertical group
	    groupLayout.setVerticalGroup(groupLayout.createSequentialGroup()
		    
		    .addPreferredGap(ComponentPlacement.UNRELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
		    .addComponent(loadingLabel)
		    .addPreferredGap(ComponentPlacement.UNRELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	    );
	    
	    
	  }
	  return loadingPanel;	    
    }
	


	/**
	 * Configs this dialog
	 */
	private void configDialog() {

		getContentPane().setLayout(new BorderLayout());		
	
				
		getContentPane().add(QueryPanelControler.INSTANCE.getBoxQuerySwingPanel(), 
				BorderLayout.CENTER);
		
		setTitle(TITLE);
		
				
		pack();
		
		
		setMinimumSize(getSize());
		setPreferredSize(getSize());
		setMaximumSize(getSize());
		setResizable(false);
		
		//hack, don't know why but I have to call pack for the 2nd time
		// to make the dialog hug its panel flush
		pack();
		setLocationRelativeTo(null);// center
	}
	

}

